<?php
ini_set('display_errors', 'Off');
$kuname = "longzs";
require '../../myzhuaqu.php';
require '../../vendor/autoload.php';
require '../phpQuery.php';
require '../Lib/ORG/Puhuo.php';
$_REQUEST['url']=($_REQUEST['url']=="")?"":$_REQUEST['url'];
if($_REQUEST["re"]==""){
    $host=host($_REQUEST['url']);
    $re=getone("select puhuo from longzs.longzs_re where host='{$host}'");
    if($re==""){
        $re=="(.mp-tickettype-group-new~去哪儿门票~.mp-tickettype-overbtn.new)>>(.ticket-types-group~门票类型~.ticket-name)>>(.product-body~data)>>(.mp-description-name~sight^)(.product-title>p:first)(.product-supplier~desc)(.mp-ticket-tags.new~date)(.mp-ticket-offerprice:first~price)";
    }
    $_REQUEST['re']=$re;
}
$q = new Puhuo();
if($_REQUEST['url']!="") {
    if($_REQUEST['reset']){
        unlink("10000.html");
    }
    if($_REQUEST['element']=="") {
        $html = file_get_contents2($_REQUEST['url']);
    }else {
        $html = element2($_REQUEST['url'], $_REQUEST['element'], 10000);
    }
    $q->html($html);
    $q->loadre($re);
    $result=$q->getData();
    $newResult=array();
    $newResult["fx"]=$result;
    $newResult["puhuo"]=$q->puhuo;

}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>捕获</title>
    <style>
        form{width:100%}
        .formrow{
            height:22px;
            clear: both;
            text-align: left;
        }
        .formrow label{
            float:left;
        }
        .resone{
            width:100%;
            clear:both;
        }
        .res textarea{
            width:49%!important;
            float:left!important;
        }
        input,textarea{
            float:left;
            width:98%;
        }
        textarea{
            float:left;
            height:500px;
        }
        textarea[name="re"]{
            height:56px;
        }
        input[type="submit"]{
            width:120px;
            height:24px;
        }
        input[type="checkbox"]{
            width:auto;
        }

        </style>
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
        function copyToClipboard(txt) {
            if (window.clipboardData) {
                window.clipboardData.clearData();
                window.clipboardData.setData("Text", txt);
                alert("复制成功！")
            } else if (navigator.userAgent.indexOf("Opera") != -1) {
                window.location = txt;
                alert("复制成功！");
            } else if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                } catch (e) {
                    alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
                }
                var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
                if (!clip)
                    return;
                var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
                if (!trans)
                    return;
                trans.addDataFlavor('text/unicode');
                var str = new Object();
                var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
                var copytext = txt;
                str.data = copytext;
                trans.setTransferData("text/unicode", str, copytext.length * 2);
                var clipid = Components.interfaces.nsIClipboard;
                if (!clip)
                    return false;
                clip.setData(trans, null, clipid.kGlobalClipboard);
                alert("复制成功！")
            }else if(copy){
                copy(txt);
                alert("复制成功！")
            }
        }
        function selectre(re,that){
            //window.clipboardData.setData('text',re)
            alert(re);
            document.execCommand("Copy");
        }
    </script>
</head>
<form method="post">
    <div class="formrow"><label>网址:</label><input type="text" name="url" value="<?=$_REQUEST['url']?>"/></div>
    <div class="formrow"><label>element(如果正则存在则用element获取网页,默认留空):</label><input type="text" name="element" value="<?=$_REQUEST['element']?>"/>
    <div class="formrow"><label>re：</label><br><textarea name="re"><?=$_REQUEST['re']?></textarea></div>
    <div class="formrow"><label>清缓存:</label><input type="checkbox" name="reset" value="true"/></div>
    <div class="formrow"><label>执行：</label><input type="submit" name="执行" value="执行"/></div>
    <div class="formrow"><label>结果：</label><textarea name="result"><?=print_r($newResult,1)?></textarea></div>
</form>
<?php if(!empty($q->html)){
    for($i=0;$i<count($q->html);$i++) {?>
        <div class="resone">
<?php
        $q->xre[$i]=preg_replace("/\(|\)|\.|\\\#/"," ",$q->xre[$i]);
        $q->xre[$i]=preg_replace("/([^\s]+)/","    <a href='javascript:void(0)' onclick='selectre(\"\\1\",this)'>\\1</a>",$q->xre[$i])
        ?>
            <p><?="【".$q->xname[$i]."】".$q->xre[$i]?></p>
    <div class="res">
        <textarea id="html<?=$i?>"><?=htmlspecialchars(html_entity_decode($q->html[$i]))?></textarea>
        <textarea id="metchedhtml<?=$i?>"><?=htmlspecialchars(html_entity_decode($q->html2[$i]))?></textarea>
    </div>
</div>
<?php }
}
?>
</body>
</html>

